package com.dk.mq;

import com.aliyuncs.exceptions.ClientException;
import com.dk.pojo.user.SmsSend;
import com.dk.service.SmsService;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Component
@RocketMQMessageListener(topic = "dongdongshop-Sms",consumerGroup = "consumer-1905")
public class SmsConsumerMq implements RocketMQListener<SmsSend> {

    @Autowired
    private SmsService smsService;

    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    public void onMessage(SmsSend smsSend) {
        HashOperations hashOperations = redisTemplate.opsForHash();
        hashOperations.put("user_register",smsSend.getPhone(),smsSend.getCode());
        try {
//            smsService.sendSms(smsSend.getCode(),smsSend.getPhone());
            smsService.sendSmsByApl(smsSend.getCode(),smsSend.getPhone());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
